package com.lightjet.macross.base.upms.domain;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.lightjet.macross.common.core.StringKeyBaseEntity;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.HashSet;
import java.util.Set;

@Entity
@Table(name="SYS_ORGANIZATION")
@Getter
@Setter
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler","createDate","updateDate"})
public class SysOrganization extends StringKeyBaseEntity{
    public SysOrganization()
    {

    }
    public SysOrganization(String id)
    {
        super(id);
    }

    /**父组织*/
    @ManyToOne
    @JoinColumn(name="parentid")
    @JsonBackReference
    SysOrganization parent;

    /** description:显示名称  */
    @NotNull(message="显示名称不能为空")
    private String displayname;

    /** description:单位简称  */
    private String shortname;

    /** description:单位编号  */
    private String organcode;

    /** description:备注  */
    private String memo;

    /** description:排序值  */
    private Integer sort = 0;

    /** description:是否启用  */
    private byte isenable = 1;

    /** description:获取子集  */
    @OneToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY)
    @JoinColumn(name="parentid")
    /*@JsonIgnore*/
    @JsonManagedReference
    private Set<SysOrganization> children = new HashSet<>();
}
